#pragma once
#include"macro/xmaybe_unused.hpp"
// 兼容 virtual c++，gcc 系列可以直接使用 __attribute__((used))

#define xkeep_str_begin()                                                                       \
    constexpr int __words_str_begin = __COUNTER__;                                              \
    template<int i_v> struct __mixc_keep_struct{ static inline constexpr int value = i_v;  };   \
    inline void __mixc_keep_str(__mixc_keep_struct<__COUNTER__>){  }                            \

#define xkeep_str(NAME,...)                                             \
    inline const char * NAME = __VA_ARGS__;                             \
    inline void __mixc_keep_str(__mixc_keep_struct<__COUNTER__> item){  \
        volatile auto __dummy = NAME;                                   \
        (void)__dummy;                                                  \
                                                                        \
        if constexpr (item.value - 1 != __words_str_begin){             \
            __mixc_keep_str(__mixc_keep_struct<item.value - 1>{});      \
        }                                                               \
    }

#define xkeep_str_array(NAME,...)                                       \
    inline const char * NAME[] = __VA_ARGS__;                           \
    inline void __mixc_keep_str(__mixc_keep_struct<__COUNTER__> item){  \
        volatile auto __dummy = NAME;                                   \
        (void)__dummy;                                                  \
                                                                        \
        if constexpr (item.value - 1 != __words_str_begin){             \
            __mixc_keep_str(__mixc_keep_struct<item.value - 1>{});      \
        }                                                               \
    }

#define xkeep_str_end()                                                 \
    struct __mixc_keep_str_struct{                                      \
        __mixc_keep_str_struct(){                                       \
            volatile bool dummy = false;                                \
            /*并不真正执行，而是让编译器假定有代码用到这些字符串*/      \
            if (dummy){                                                 \
                __mixc_keep_str(__mixc_keep_struct<__COUNTER__ - 1>{}); \
            }                                                           \
        }                                                               \
    };                                                                  \
    xmaybe_unused inline __mixc_keep_str_struct __for_mixc_keep_str;    \

